package com.example.haha_.ui_demo.recyclerview;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.haha_.ui_demo.R;
import com.example.haha_.ui_demo.beans.Shop;
import com.example.haha_.ui_demo.retrofitservice.Retrofitservice;
import com.google.gson.Gson;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import okhttp3.ResponseBody;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import com.squareup.picasso.Picasso;

public class RecyclerActivity extends AppCompatActivity {
    private ImageView imageView;
    private TextView textView1;
    public String str="-";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_recycler);
        //定义适配器对象
        RecyclerViewAdapter adapter = new RecyclerViewAdapter();
        //获取数据
        adapter.setData(getData());
        //需将布局中的RecyclerView对象的id指定为recyclerview
        RecyclerView recyclerView = findViewById(R.id.recyclerView);
        //定义线性⽅式显示数据
        LinearLayoutManager layoutManager =
                new LinearLayoutManager(RecyclerActivity.this);
        //设置为位垂直⽅式显示（也可以⽔平⽅式显示）
        layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        //设置布局管理器
        recyclerView.setLayoutManager(layoutManager);
        //设置适配器
        recyclerView.setAdapter(adapter);
        //以下代码为添加分割线（需⾃⼰完成）
        recyclerView.addItemDecoration(new DividerItemDecoration(this,DividerItemDecoration.VERTICAL));
    }
    //获取数据集合
    private List<DataItem> getData(){
        List<DataItem> data = new ArrayList<>();
        for (int i = 0; i < 5; i ++){
            DataItem dataItem = new DataItem();
//            String s=load(i);
            System.out.println("///////////"+str+"*********************"+"\n");
            dataItem.setUrl("image" + i);
            dataItem.setText1("text1:" + i);
            dataItem.setText2("text2:" + i);
            data.add(dataItem);
        }
        return data;
    }


}
